package cn.exrick.xboot.flow.controller;


import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.config.custom.CustomPageUtils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.exrick.xboot.flow.entity.FlowUserinfo;
import cn.exrick.xboot.flow.service.IFlowUserinfoService;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @author zy
 * @since 2022-08-31
 */
@RestController
@RequestMapping("/order/flowUserinfo")
public class FlowUserinfoController {
    private final Logger logger = LoggerFactory.getLogger(FlowUserinfoController.class);

    @Autowired
    public IFlowUserinfoService iFlowUserinfoService;

    /**
     * 分页查询数据
     *
     * @param page         分页信息
     * @param flowUserinfo 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getFlowUserinfoPageList")
    public Result<Object> getHontUserList(Page<FlowUserinfo> page, FlowUserinfo flowUserinfo) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iFlowUserinfoService.selectPage(page, flowUserinfo)));
    }

    /**
     * 保存和修改公用的
     *
     * @param flowUserinfo 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowUserinfoSave")
    public Result<Object> flowUserinfoSave(FlowUserinfo flowUserinfo) {
        iFlowUserinfoService.saveOrUpdate(flowUserinfo);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/flowUserinfoGetById")
    public Result<Object> flowUserinfoGetById(String id) {
        FlowUserinfo byId = iFlowUserinfoService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowUserinfoDelete")
    public Result<Object> hontUserDelete(String id) {
        iFlowUserinfoService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/flowUserinfoBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iFlowUserinfoService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    /**
     * 根据模板id获取被审核人
     * @param templateId
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/getUserinfoOnHontUser")
    public Result<Object> getUserinfoOnHontUser(String templateId) {

        return iFlowUserinfoService.getUserinfoOnHontUser(templateId);
    }
}
